package com.config;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.plugin.druid.DruidStatViewHandler;
import com.jfinal.template.Engine;
import com.model.YsUser;
import com.spring.SpringPlugin;

public class CoreConfig extends JFinalConfig {
	public static void main(String[] args) {
		JFinal.start("WebContent", 7855, "/", 5);
	}

	/**
	 * 配置常量
	 */
	public void configConstant(Constants me) {
		PropKit.use("config.txt");
		me.setDevMode(true);
	}

	/**
	 * 配置路由
	 */
	public void configRoute(Routes me) {
	}

	public void configEngine(Engine me) {

	}

	/**
	 * 配置插件
	 */
	public void configPlugin(Plugins me) {
		// 启动Spring插件
		me.add(new SpringPlugin("classpath:applicationContext.xml"));

		// 配置C3p0数据库连接池插件
		DruidPlugin druidPlugin = new DruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"),
				PropKit.get("password").trim());
		me.add(druidPlugin);

		// 配置ActiveRecord插件
		ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
		// 所有映射在 MappingKit 中自动化搞定
		arp.addMapping("ys_user", YsUser.class);
		me.add(arp);
	}

	/**
	 * 配置全局拦截器
	 */
	public void configInterceptor(Interceptors me) {

	}

	/**
	 * 配置处理器
	 */
	public void configHandler(Handlers me) {
		me.add(new DruidStatViewHandler("/druid"));
	}
}
